package com.icss.daos;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.icss.beans.EnrollQAVO;

/**
 * @author 韦锦良
 *　类的作用：招生问答逻辑处理类
 * 最后修改时间：2010-3-24　下午01:01:19
 * 最后的改动内容：初始版本
 */
public class EnrollQADao {

	private Dao dao = new Dao();

	private ResultSet rs = null;
	
	
	//通过编号获得相关的招生问答信息
	public EnrollQAVO getEnrollQAVOById(String qaID) {

		EnrollQAVO vo = null;

		String sql = "select * from EnrollQA where qaID=" + qaID;

		rs = dao.query(sql);

		vo = getVOFromResultSet(rs).get(0);

		close();

		return vo;

	}

	//从结果集封装到vo类里面去
	public ArrayList<EnrollQAVO> getVOFromResultSet(ResultSet rs) {

		ArrayList<EnrollQAVO> vos = new ArrayList<EnrollQAVO>();

		try {
			while (rs.next()) {
				EnrollQAVO vo = new EnrollQAVO();
				vo.setAnswer(rs.getString("answer"));
				vo.setQaID(rs.getInt("qaID"));
				vo.setQuestion(rs.getString("question"));
				vos.add(vo);
			}

		} catch (SQLException e) {
			e.printStackTrace();
		}

		return vos;

	}


	//获得所有的招生问答
	public ArrayList<EnrollQAVO> getAllEnrollQA() {

		ArrayList<EnrollQAVO> vos = null;

		String sql = "select * from EnrollQA order by qaID ";

		rs = dao.query(sql);

		vos = getVOFromResultSet(rs);

		close();

		return vos;
	}

	//关闭连接
	public void close() {

		try {

			if (null != rs) {
				rs.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}

		dao.close();

	}
	
	//执行给定的sql语句
	public boolean execute(String sql) {
		return dao.execute(sql);
	}

}
